package com.csdj.essay.common;

import com.csdj.essay.utils.MessageUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * mvc 返回固定的json数据格式
 */
public class WebResult {
    //错误代码
    private int code;
    //错误消息
    private String msg;
    //数据
    private Map<String, Object> result = new HashMap<>();

    public WebResult() {
    }

    public WebResult(int code) {
        this.code = code;
        this.msg = MessageUtil.getMsg(code);
    }


    public WebResult(int code, Object data) {
        this.code = code;
        this.result.put("data", data);
    }

    /**
     * 添加数据
     *
     * @param key
     * @param data
     * @return
     */
    public WebResult putData(String key, Object data) {
        this.result.put(key, data);
        return this;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getResult() {
        return result;
    }

    public void setResult(Map<String, Object> result) {
        this.result = result;
    }
}